from datetime import datetime
from app import db


class MealLog(db.Model):
    __tablename__ = 'meal_logs'

    log_id = db.Column(db.Integer, primary_key=True, autoincrement=True)  # 打卡记录ID
    user_id = db.Column(db.Integer, nullable=False)  # 用户ID，假设用户表已经存在
    meal_id = db.Column(db.Integer, db.ForeignKey('meals.meal_id'), nullable=False)  # 关联的餐食ID
    photo = db.Column(db.String(255))  # 打卡照片的URL
    comment = db.Column(db.Text)  # 用户评论
    appetite_score = db.Column(db.Integer)  # 食欲评分，范围：1-5
    nutrition_score = db.Column(db.Integer)  # 营养评分，范围：1-5
    fullness_score = db.Column(db.Integer)  # 饱腹评分，范围：1-5
    created_at = db.Column(db.DateTime, default=datetime.utcnow)  # 打卡时间

    meal = db.relationship('Meal', backref=db.backref('meal_logs', lazy=True))  # 与meals表的关联
